﻿using System.Windows.Forms;

namespace NoteHelper.BaseControl
{
    public class Helper4NumericUpDown : IControlHelper
    {
        public object GetValue(Control control)
        {
            var number = (NumericUpDown)control;
            return number.Value;
        }

        public void SetValue(Control control, object value)
        {
            var number = (NumericUpDown)control;
            if (value == null)
            {
                number.Value = 0;
                return;
            }
            decimal d = (decimal)value;
            if (d < number.Minimum)
                d = number.Minimum;
            if (d > number.Maximum)
                d = number.Maximum;
            number.Value = d;
        }
    }
}
